package com.deer.wms.instock.web;

import cn.hutool.core.util.ObjectUtil;
import com.deer.wms.ASN.manage.model.asn.AsnMaster;
import com.deer.wms.ASN.manage.model.asn.AsnMasterCriteria;
import com.deer.wms.ASN.manage.service.AsnMasterService;
import com.deer.wms.instock.service.WaveService;
import com.deer.wms.intercept.annotation.User;
import com.deer.wms.intercept.common.data.CurrentUser;
import com.deer.wms.project.root.core.result.Result;
import com.deer.wms.project.root.core.result.ResultGenerator;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import springfox.documentation.annotations.ApiIgnore;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Author: xu
 * @Date: 2022/06/23/11:23
 * @Description:
 */
@Api(description = "直发虚仓，VMI特殊处理接口")
@RestController
@RequestMapping("/wave")
public class WaveController {
    @Autowired
    private WaveService waveService;

    @Autowired
    private AsnMasterService asnMasterService;


    @ApiOperation("id查Code")
    @GetMapping("findCode")
    public Result findCode(String ids,String asnStockId) {
        //471713 VMI
        //直发虚仓待定
        List<String> waveDetailIds = Arrays.asList(ids.split(","));
        List<String> boxCode = waveService.findCode(waveDetailIds, 471713);
        return ResultGenerator.genSuccessResult(boxCode);
    }


    @ApiOperation(value = "WMS产品入库(数据回传ERP)", notes = "WMS产品入库(数据回传ERP)")
    @GetMapping("/toPutaway")
    public Result toPutaway(AsnMasterCriteria criteria, @ApiIgnore @User CurrentUser currentUser) {
        // 获取选中的入库任务
        // 解析前台
        List<Integer> idList=new ArrayList<>();
        String ids = criteria.getIds();
        if(ids!=null&&!ids.equals("")){
            // 按照逗号分隔成多个任务单号
            String[] list = ids.split(",");
            for(String id : list){
                idList.add(Integer.parseInt(id));
            }
        }
        List<AsnMaster> asnMasters=asnMasterService.listByIds(idList);
        // 每一条明细对应一个库存事务
        for(AsnMaster asnMaster:asnMasters){
//            waveService.accomplish(asnMaster, criteria.getCellCode(), currentUser);

        }
        return ResultGenerator.genSuccessResult();



    }
}
